package cn.lf.android.lawfirm.outgoingregistration.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import cn.lf.android.lawfirm.R;
import cn.lf.android.lawfirm.outgoingregistration.OutGoingRegistrationActivity;
import cn.lf.android.lawfirm.outgoingregistration.modle.OutGoing;

/**
 * Created by Administrator on 2017/8/22.
 */

public class OutGoingRegistrationAdapter extends BaseAdapter {

    private List<OutGoing> list;
    private Context context;
    private LayoutInflater inflater;

    public OutGoingRegistrationAdapter(List<OutGoing> list, Context context) {
        this.list = list;
        this.context = context;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup viewGroup) {
        ViewHolder holder;
        if (null == convertView) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_outgoingregistration, null);
            holder.subtitle = (TextView) convertView.findViewById(R.id.tv_data);
            holder.content = (TextView) convertView.findViewById(R.id.tv_time);
            holder.mEdit = (TextView) convertView.findViewById(R.id.tv_edit);
            holder.title = (TextView) convertView.findViewById(R.id.head_left);
            convertView.setTag(holder);
        } else {
            holder = ((ViewHolder) convertView.getTag());
        }
        OutGoing bean = list.get(position);
        holder.subtitle.setText(bean.subtitle);
        holder.content.setText(bean.content);
        holder.title.setText(bean.title);
        if ("y".equals(bean.idEditEnable)) {
            holder.mEdit.setVisibility(View.VISIBLE);
        } else {
            holder.mEdit.setVisibility(View.GONE);
        }
        holder.mEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ((OutGoingRegistrationActivity) context).onEdit(position);
            }
        });
        return convertView;
    }

    class ViewHolder {
        private TextView content;//
        private TextView subtitle;//
        private TextView mEdit;//
        private TextView title;//
    }
}
